package com.hunt.model.app;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.text.DecimalFormat;

@Data
@NoArgsConstructor
@ToString
public class StockAllMessage {
    private double newprice;
    //最新价格
    private double average;
    //平均价格
    private double high;
    //最高价格
    private double low;
    //最低价格
    private double open;
    //开盘价
    private double preclose;
    //昨日收盘价
    private String turnover;
    //成交额
    private String vol;
    //成交量
    private double qrr;
    //量比
    private String floatsharesstock;
    //流通股
    private String floatsharesstockvol;
    //流通值
    private String totalsharestock;
    //总股本
    private String mv;
    //总市值
    private double pe;
    //动态市盈率
    private  double downlimit;
    //跌停
    private  double upperlimit;
    //涨停
    private String handchange;
    //换手率
    public StockAllMessage(double newprice, double average, double high, double low, double open, double preclose, double vol,double turnover,  double qrr, double floatsharesstock, double floatsharesstockvol,double totalsharestock, double mv, double pe,
    double downlimit,double upperlimit,double handchange) {
        this.newprice = doubleformate(newprice);
        this.average = doubleformate(average);
        this.high = doubleformate(high);
        this.low = doubleformate(low);
        this.open = doubleformate(open);
        this.preclose = doubleformate(preclose);
        this.turnover = strformate(turnover);
        this.vol =  strformate(vol);
        this.qrr =doubleformate(qrr);
        this.floatsharesstock = strformate(floatsharesstock);
        this.floatsharesstockvol = strformate(floatsharesstockvol);
        this.totalsharestock = strformate(totalsharestock);
        this.mv =  strformate(mv);
        this.pe = doubleformate(pe);
        this.downlimit=doubleformate(downlimit);
        this.upperlimit=doubleformate(upperlimit);
        this.handchange= strformate(handchange);
    }
    //保留2位小数加上合适的位数
    private String strformate(double money){
            if(Math.abs(money/100)>1&&Math.abs(money/1000000)<1){
                double result=money/10000;
                return  String.format("%.2f", result)+"万";
            }
            if(Math.abs(money/1000000)>1){
                double result=money/100000000;

                return   String.format("%.2f", result)+"亿";
            }
            if(Math.abs(money)<1&&Math.abs(money)>0)  {
                return String.format("%.2f", money*100)+"%";
            }
            else {
                return  String.format("%.2f", money);
            }

    }
    private double doubleformate(double money){
        return  Double.parseDouble(String.format("%.2f", money));
    }

}
